/**
 * 1.构造函数注入跟setter方法注入可以混用,后者会覆盖前者
 * 2.若有多个符合要求的构造函数，那么Spring会采用默认的无参构造进行实例化
 */
package com.example.demospringbootbean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.beans.ConstructorProperties;

public class ClassB {
    private String name;
    private int age;
    private ClassC classC;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }



    public ClassB(){};

    //构造器注入，通过Autowired指定使用这个构造函数，否则默认会使用无参
    public ClassB(String name, int age, ClassC classC) {
        AppContextUtil.printlng("ClassB constructing...构造器注入ClassC到ClassB中" );
        this.name = name;
        this.age = age;
        this.classC = classC;
    }

//    @Autowired
//    public ClassB(@Value("zs")String name, @Value("20")int age, ClassC classC) {
//        AppContextUtil.printlng("ClassB constructing...构造器注入ClassC到ClassB中" );
//        this.name = name;
//        this.age = age;
//        this.classC = classC;
//    }


    //Setter注入，
    @Autowired
    public void setClassC(ClassC classC) {
        AppContextUtil.printlng("setClassC：Setter注入ClassC到ClassB中" );
        this.classC = classC;
    }

    //使用工厂方法注入
//    @Autowired
    public void setClassC() {
        AppContextUtil.printlng("setClassC：Setter注入ClassC到ClassB中" );
        this.classC =  ClassCFactory1.getClassFromStaticFactory() ;
//        this.classC =  new ClassCFactory1().getClassFromInstanceFactory();
    }

    public ClassC getClassC() {
        return classC;
    }

    public void spellCheck() {
        classC.checkSpelling();
    }

    public void showInfo(){
        AppContextUtil.printlnr("name="+name+";age="+age+";ClassC="+classC);
    }
}
